<template>
  <!-- 搜索功能 -->
  <el-form
    :inline="true"
    :model="options"
  >
    <el-form-item>
      <el-input
        @input="inputHan"
        size="small"
        v-model="queryInfo[keyword]"
        :placeholder="options.placeholder"
      ></el-input>
    </el-form-item>
    <el-form-item
      v-if="options.isStateShow"
      :label="options.sapntext2"
    >
      <el-select
        size="small"
        v-model="queryInfo.state"
        placeholder="请选择"
      >
        <el-option
          label="启用"
          :value="1"
        ></el-option>
        <el-option
          label="禁用"
          :value="0"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-button
      size="small"
      @click="clear"
    >清空</el-button>
    <el-button
      size="small"
      type="primary"
      @click="$emit('search')"
    >搜索</el-button>
  </el-form>
</template>

<script>
export default {
  name: 'SearchKeyword',
  props: {
    options: {
      type: Object,
      required: true
    },
    queryInfo: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      keyword: ''
    }
  },
  created () {
    this.keyword = this.options.keyword || 'keyword'
  },
  methods: {
    // 清空，重置数据
    clear () {
      this.queryInfo[this.keyword] = this.queryInfo.state = null
      this.$emit('search')
    },

    //
    inputHan () {
      if (this.queryInfo[this.keyword] === '') {
        this.$emit('search')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form-item {
  width: 200px;
  height: 36px;
  line-height: 36px;
}
</style>
